package com.config;



import com.utils.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 异常处理类
 *
 * @author qiaogong
 * @date 2021/03/29
 */
@ControllerAdvice
public class ExceptionHander {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public Object handerException(HttpServletRequest req, Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
        return AjaxResult.error("系统异常！");
    }

}
